package com.example.managesystem.service.impl;

import com.example.managesystem.dao.userMapper;
import com.example.managesystem.entity.user;
import com.example.managesystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class userServiceImpl implements UserService {
    @Autowired
    private userMapper UserMapper;

    //登入
    @Override
    public List<user> selectUser(user user) {
        List<user> list = UserMapper.selectUser(user);
        if(list.size()!=0){
            return list;
        }else{
            return null;
        }
    }

    @Override
    public String add(user user) {
        user.setImage("/images/avatars/0.jpg");
        user.setAddress("4577");
        user.setDescription("");
        try {
            UserMapper.add(user);
        }catch (Exception e){
            return "注册失败";
        }
        return "注册成功";
    }

    @Override
    public List<user> selectAll() {
        return UserMapper.selectAll();
    }

    @Override
    public user selectUserInfo(String name) {
        return UserMapper.selectUsertUserInfo(name);
    }

    @Override
    public int Update(user user) {
        if( UserMapper.updateUser(user)==1){
            return 1;
        }else{
            return 0;
        }


    }


}
